package subumbo.micro.controller
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	public class MultiViewController extends Component
	{
		protected var _views:Dictionary;
		protected var _selectedView:DisplayObject;
		protected var _state:String;
		
		override protected function init(e:Event):void
		{
			super.init(e);
			_views = new Dictionary();
		}
		
		protected function addSubView(view:DisplayObject, id:String):void
		{
			if(_views[id]) throw new Error("MultiViewController: Id already in use.");
			_views[id] = view;
			view.visible = false;
			this.addChild(view);
		}
		
		protected function showView(id:String):DisplayObject
		{
			var view:DisplayObject = _views[id];
			view.alpha = 1;
			view.visible = true;
			_state = id;
			return view;
		}
		
		protected function hideView(id:String):DisplayObject
		{
			return _views[id];
		}
		
		protected function onHidden():void
		{
			_selectedView.visible = false;	
		}
	}
}